
import AuthenticationService from '../shared/services/authentication-service';
import HttpRequestService from '../shared/services/http-request-service';
import TokenService from '../shared/services/token-service';

export default class AuthService {
  private static readonly url = '/authentication';

  static async checkOnUsername(username: string): Promise<boolean> {
    const response = await HttpRequestService.get(`${this.url}/checkOnUsername`, {
      username: username,
    });

    return response.payload.usernameExists;
  }

  /**
   * Login with provided [username] and [password]. The user basic info will be return.
   */
  static async login(username: string, password: string): Promise<any> {
    // TODO: Applies real deviceInfo & systemInfo as needed.
    const response = await HttpRequestService.post(`${this.url}/login`, {
      username: username,
      password: password,
      deviceInfo: {},
      systemInfo: {},
    });

    return response.payload;
  }

  static logout(): void {
    // Removes local user info.
    AuthenticationService.removeUserInfo();

    // Removes local token info.
    TokenService.removeToken();
  }
}